package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.found.common.entity.open.*;
import com.ibeeking.gmc.global.api.common.dto.OauthClientDTO;
import com.ibeeking.gmc.global.api.feign.GlobalOpenFeignClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalOpenFeignFallbackFactory implements FallbackFactory<GlobalOpenFeignClient> {
    @Override
    public GlobalOpenFeignClient create(Throwable throwable) {
        return new GlobalOpenFeignClient() {
            @Override
            public ResponseResult<OauthClientDTO> queryByClientId(String clientId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询授权客户端失败。");
            }

            @Override
            public ResponseResult<List<OpenConfigDTO>> queryOpenConfigList(OpenConfigQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询开放平台配置失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<OpenConfigDTO> queryOpenConfigOne(OpenConfigQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询开放平台配置失败。", null);
            }

            @Override
            public ResponseResult<List<OpenAuthDTO>> queryOpenAuthList(OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询授权微信平台失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<List<SimpleOpenAuthDTO>> querySimpleOpenAuthList(OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询授权微信平台失败。", Collections.emptyList());
            }

            @Override
            public ResponseResult<OpenAuthDTO> queryOpenAuthOne( OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询授权微信平台失败。", null);
            }

            @Override
            public ResponseResult<SimpleOpenAuthDTO> querySimpleOpenAuthOne(OpenAuthQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询授权微信平台失败。", null);
            }
        };
    }
}
